package com.x.reader.dao;

import com.x.framework.Base;
import com.x.framework.dao.BaseDao;
import com.x.reader.model.Favourite;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class FavouriteDao extends BaseDao {

    private final static String selectFavouriteListSql = "select t1.* from reader_favourite t1 where user_id = ? ";

    public List<Favourite> selectFavouriteList(Favourite favourite) throws Exception {
        StringBuilder sb = new StringBuilder(selectFavouriteListSql);
        List params = new ArrayList();
        params.add(favourite.getUserId());
        if (Base.isNotNull(favourite.getCategoryId())) {
            sb.append("and t1.CATEGORY_ID = ? ");
            params.add(favourite.getCategoryId());
        }
        if (Base.isNotNull(favourite.getFavouriteId())) {
            sb.append("and t1.FAVOURITE_ID = ? ");
            params.add(favourite.getFavouriteId());
        }
        sb.append("order by favourite_create_time desc ");
        return this.queryForList(sb.toString(), Favourite.class, params, favourite);
    }

}
